#include "j.h"

J::J()
{
    status = 0;
}

J::J(QImage img)
{
    cells[0] = new Cell(0,3,img);
    cells[1] = new Cell(0,4,img);
    cells[2] = new Cell(0,5,img);
    cells[3] = new Cell(-1,3,img);
    status = 0;
}


void J::rotate(int d){
    if(d == -1){
        --status;
        if(status == -1){
            status = 3;

        }
    }
    if(status == 0){
        cells[0]->row += d* 1,cells[0]->col += d* 1;
        cells[2]->row += d* -1,cells[2]->col += d* -1;
        cells[3]->row += d* 2,cells[3]->col += d* 0;

    }else if(status == 1){
        cells[0]->row += d* -1,cells[0]->col += d* 1;
        cells[2]->row += d* 1,cells[2]->col += d* -1;
        cells[3]->row += d* 0,cells[3]->col += d* 2;

    }else if(status == 2){
        cells[0]->row += d* -1,cells[0]->col += d* -1;
        cells[2]->row += d* 1,cells[2]->col += d* 1;
        cells[3]->row += d* -2,cells[3]->col += d* 0;

    }else if(status == 3){
        cells[0]->row += d* 1,cells[0]->col += d* -1;
        cells[2]->row += d* -1,cells[2]->col += d* 1;
        cells[3]->row += d* 0,cells[3]->col += d* -2;

    }
    if(d == 1){
        ++status;
        if(status == 4){
            status = 0;

        }
    }
}
